package com.example.gustavo.hello.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.gustavo.hello.R;

/**
 * Created by gustavo on 2015/6/24.
 */
public class CheckableLayout extends LinearLayout implements Checkable{

    private RadioButton rb;

    public CheckableLayout(Context context) {
        super(context);
        init(context);
    }

    public CheckableLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);

    }

    public CheckableLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);

    }


    private void init(Context context){


        View view = View.inflate(context, R.layout.checkable_layout, this);
        rb = (RadioButton) view.findViewById(R.id.rb);

    }


    @Override
    public void setChecked(boolean checked) {
        if (rb != null) {
            rb.setChecked(checked);
        }
    }

    @Override
    public boolean isChecked() {
        return rb.isChecked();
    }

    @Override
    public void toggle() {

        rb.toggle();
    }
}
